 ///
 /// @file    SplitTool.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-31 16:18:15
 ///
 
#include "SplitTool.h"
#include <NLPIR.h>
#include <stdio.h>
#include <iostream>
#include <sstream>

using std::cout;
using std::endl;
using std::istringstream;

SplitToolNLPIR::SplitToolNLPIR(wd::Configuration & conf)
: _conf(conf)
{
	cout << _conf.getConfigMap()["NLPIR"] << endl;	
	if(!NLPIR_Init(_conf.getConfigMap()["NLPIR"].c_str(), UTF8_CODE))
	{
		printf("NLPIR init failed!\n");
	}
}

vector<string> SplitToolNLPIR::cut(const string & sentence)
{
	const char * sResult;
	sResult = NLPIR_ParagraphProcess(sentence.c_str(), 0);
	string result(sResult);
	istringstream iss(result);
	string word;
	vector<string> vecWords;
	vecWords.reserve(1000);
	while(iss >> word)
	{
		vecWords.push_back(word);
	}
	return vecWords;
}

SplitToolNLPIR::~SplitToolNLPIR()
{
	NLPIR_Exit();
}
